﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Globalization;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.APP.Classes;
using _WebShared.Classes;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_EmployeePersonalHistories : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        IEmployeeBLL empBLL = new EmployeeBLL();
        //I_HRM_PS_EmployeeParents parent = new B_HRM_PS_EmployeeParents();
        IHisSpouseBLL spouBLL = new HisSpouseBLL();
        IChildrenBLL chilBLL = new ChildrenBLL();
        //I_HRM_PS_EmployeeContacts cont = new B_HRM_PS_EmployeeContacts();
        //I_HRM_PS_EmployeeNameHistories name = new B_HRM_PS_EmployeeNameHistories();
        Main main = new Main();

        //private EmployeeInfo empInfo;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadHeader();
            //LoadPanelBar();
        }

        public void LoadHeader()
        {
            //string strEmpSeq = ssMng.EmpSeq;

            //if (strEmpSeq.Length == 0)
            //    return;

            //empInfo = emp.GetEmployeeInfo(Int32.Parse(strEmpSeq));

            //lblGenderName.Text = empInfo.GenderName;
            //lblBloodGroup.Text = empInfo.BloodGroup;
            //lblRaceNationalName.Text = empInfo.RaceNatName;
            //lblNationalName.Text = empInfo.NatName;
            //lblReligionName.Text = empInfo.ReligionName;
            //lblBirthDate.Text = string.Format("{0:dd/MM/yyyy}", empInfo.BirthDate);
            //lblCitizenID.Text = empInfo.Citizen;
            //lblTaxPayerID.Text = empInfo.TaxPayer;
            //lblSocialID.Text = empInfo.Social;
            //lblDeathDate.Text = string.Format("{0:dd/MM/yyyy}", empInfo.DeathDate);

            //if (empInfo.BirthDate.HasValue)
            //{
            //    DateTime dt = (DateTime)DateTimeX.ForceToDate(empInfo.BirthDate.ToString(), true);
            //    lblAgeYear.Text = main.CalculateAge(dt).ToString();
            //    lblAgeMonth.Text = main.CalculateAgeMonth(dt).ToString();
            //    lblAgeDay.Text = main.CalculateAgeDay(dt).ToString();
            //}
            //else
            //{
            //    lblAgeYear.Text = "-";
            //    lblAgeMonth.Text = "-";
            //    lblAgeDay.Text = "-";
            //}
        }

        public void LoadPanelBar()
        {
            string strEmpSeq = ssMng.EmpSeq;
            RadGrid grd1 = null;

            for (int i = 0; i < RadPanelBar1.Items.Count; i++)
            {
                if (RadPanelBar1.Items[i].Expanded)
                {
                    switch (i)
                    {
                        case 0:
                            grd1 = (RadGrid)RadPanelBar1.Items[0].Items[0].FindControl("RadGridParentHistory");
                            //grd1.DataSource = parent.SelectEmployeeParents(strEmpSeq);
                            grd1.DataBind();
                            break;
                        case 1:
                            grd1 = (RadGrid)RadPanelBar1.Items[1].Items[0].FindControl("RadGridSpouseHistory");
                            //grd1.DataSource = spouse.SelectEmployeeSpouses(strEmpSeq);
                            grd1.DataBind();
                            break;
                        case 2:
                            grd1 = (RadGrid)RadPanelBar1.Items[2].Items[0].FindControl("RadGridChildrenHistory");
                            //grd1.DataSource = child.LoadGridEmployeeChildrens(strEmpSeq);
                            grd1.DataBind();
                            break;
                        case 3:
                            grd1 = (RadGrid)RadPanelBar1.Items[3].Items[0].FindControl("RadGridContactHistory");
                            //grd1.DataSource = cont.SelectEmployeeContacts(strEmpSeq);
                            grd1.DataBind();
                            break;
                        case 4:
                            grd1 = (RadGrid)RadPanelBar1.Items[4].Items[0].FindControl("RadGridNameHistory");
                            //grd1.DataSource = name.SelectEmployeeNameHistories(strEmpSeq);
                            grd1.DataBind();
                            break;
                    }
                }
            }
        }

        protected void RadPanelBar1_ItemClick(object sender, RadPanelBarEventArgs e)
        {
            string strEmpSeq = ssMng.EmpSeq;
            RadGrid grd1 = null;

            if (e.Item.Expanded)
            {
                switch (e.Item.Index)
                {
                    case 0:
                        grd1 = (RadGrid)RadPanelBar1.Items[0].Items[0].FindControl("RadGridParentHistory");
                        //grd1.DataSource = parent.SelectEmployeeParents(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 1:
                        grd1 = (RadGrid)RadPanelBar1.Items[1].Items[0].FindControl("RadGridSpouseHistory");
                        //grd1.DataSource = spouse.SelectEmployeeSpouses(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 2:
                        grd1 = (RadGrid)RadPanelBar1.Items[2].Items[0].FindControl("RadGridChildrenHistory");
                        //grd1.DataSource = child.LoadGridEmployeeChildrens(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 3:
                        grd1 = (RadGrid)RadPanelBar1.Items[3].Items[0].FindControl("RadGridContactHistory");
                        //grd1.DataSource = cont.SelectEmployeeContacts(strEmpSeq);
                        grd1.DataBind();
                        break;
                    case 4:
                        grd1 = (RadGrid)RadPanelBar1.Items[4].Items[0].FindControl("RadGridNameHistory");
                        //grd1.DataSource = name.SelectEmployeeNameHistories(strEmpSeq);
                        grd1.DataBind();
                        break;
                }
            }
        }

        protected void RadGrid_ItemCommand(object source, GridCommandEventArgs e)
        {
            RadGrid grd1 = (RadGrid)source;
            string strEmpSeq = ssMng.EmpSeq;
            
            switch (grd1.ID)
            {
                case "RadGridParentHistory":
                    //grd1.DataSource = parent.SelectEmployeeParents(strEmpSeq);
                    break;
                case "RadGridSpouseHistory":
                    //grd1.DataSource = spouse.SelectEmployeeSpouses(strEmpSeq);
                    break;
                case "RadGridChildrenHistory":
                    //grd1.DataSource = child.LoadGridEmployeeChildrens(strEmpSeq);
                    break;
                case "RadGridContactHistory":
                    //grd1.DataSource = cont.SelectEmployeeContacts(strEmpSeq);
                    break;
                case "RadGridNameHistory":
                    //grd1.DataSource = name.SelectEmployeeNameHistories(strEmpSeq);
                    break;
            }

            if (e.CommandName != RadGrid.ExpandCollapseCommandName)
            {
                grd1.DataBind();
            }
        }

        public string GetTrueFalseImage(string strCompare, string strTrue, string strFalse
            , string strTrueImageUrl, string strFalseImageUrl)
        {
            if (strCompare == strTrue)
                return strTrueImageUrl;
            else if (strCompare == strFalse)
                return strFalseImageUrl;
            else
                return null;
        }
    }
}